package leetcode_acm.stackAndQueue;

import org.junit.Test;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月22日 13:58
 */
public class MyStack {
    //一个队列实现栈
    private final Queue<Integer> in;
    public MyStack() {
        in = new LinkedList<>();
    }

    public void push(int x) {
        in.offer(x);
    }

    public int pop() {
        if(in.isEmpty()){
            return -1;
        }
        int size = in.size();
        while(size != 1){
            in.offer(in.poll());
            size --;
        }
        return in.poll();
    }

    public int top() {
        if(in.isEmpty()){
            return -1;
        }
        int size = in.size();
        while(size != 1){
            in.offer(in.poll());
            size--;
        }
        int target = in.poll();
        in.offer(target);
        return target;
    }

    public boolean empty() {
        return in.isEmpty();
    }

}
